<?php

namespace app;

use think\response\Json;

class Result
{

    var $code;
    var $msg;
    var $data;

    public function __construct($code, $msg, $data)
    {
        $this->code = $code;
        $this->msg = $msg;
        $this->data = $data;
    }


    public static function success($data, $msg = "success"): Json
    {
        return json(new Result(200, $msg, $data));
    }

    public static function error($code, $msg): Json
    {
        return json(new Result($code, $msg, null));
    }

    /**
     * @param mixed $code
     */
    public function setCode($code): void
    {
        $this->code = $code;
    }

    /**
     * @param mixed $data
     */
    public function setData($data): void
    {
        $this->data = $data;
    }

    /**
     * @param mixed $msg
     */
    public function setMsg($msg): void
    {
        $this->msg = $msg;
    }

}